package com.liehu.web.config;

import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;
import springfox.documentation.swagger.web.SwaggerResource;
import springfox.documentation.swagger.web.SwaggerResourcesProvider;

import java.util.ArrayList;
import java.util.List;

/**
 * 使用zuul配置全局统一的swagger文档
 */
@Component
@Primary
public class DocumentationConfig implements SwaggerResourcesProvider {
    /**
     * 设定Swagger文档的资源
     * @return List<SwaggerResource>
     */
    @Override
    public List<SwaggerResource> get() {
        List<SwaggerResource> resources = new ArrayList<>();
        resources.add(swaggerResource("用户微服务", "/liehu-user/v2/api-docs", "1.0.0"));
        resources.add(swaggerResource("业务微服务", "/liehu-business/v2/api-docs", "1.0.0"));
        return resources;
    }

    /**
     * 补充文档的版本信息
     * @param name
     * @param location
     * @param version
     * @return
     */
    private SwaggerResource swaggerResource(String name, String location, String version) {
        SwaggerResource swaggerResource = new SwaggerResource();
        swaggerResource.setName(name);
        swaggerResource.setLocation(location);
        swaggerResource.setSwaggerVersion(version);
        return swaggerResource;
    }
}